<?php

namespace App\Http\Middleware;

use App\Http\Controllers\Business\App\Auth\AppAuth;
use Closure;

class ApiAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(!$request->get('token'))
        {
            echo json_encode(array(
                'status'=>'failed',
                'message'=>'认证失败，重新登录'
            ));
            exit;
        }
        else
        {
            if(AppAuth::tokenGetUserId($request->get('token')))
            {
                return $next($request);
            }
            else
            {
                echo json_encode(array(
                    'status'=>'failed',
                    'message'=>'认证失败，重新登录'
                ));
                exit;
            }
        }
    }
}
